<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org">
    <head>
        <title>authpwd</title>
        <script th:replace="@{/header.html}"></script>
    </head>
    <body>
        <h1>grant type: password</h1>
        <p th:if="@{loginError}" class="error" th:text="${errorMessage}">[...]</p>
        <form th:action="@{/oauth/token}" method="post" th:object="${session.CSRF_TOKEN}">
            <input type="text" name="username" value="user3"/>
            <input type="text" name="password" value="pwd2"/>
            <input type="text" name="grant_type" value="password"/>
            <input type="text" name="client_id" value="blogClientId"/>
            <input type="button" onclick="getAccessToken()" value="get access token"/>
        </form>
        <p><a th:href="@{/user/index}">Back to home page</a></p>
        <script th:inline="javascript">
            function getAccessToken() {
                $.ajax({
                    data: $("form").serialize(),
                    type: "post",
                    url: $("form").prop("action"),
                    timeout: 2000,
                    ContentType: "application/x-www-form-urlencoded;charset=urf-8",
                    dataType: "json",
                    headers: {
                        Authorization: 'Basic '+Base64.encode("blogClientId:secret"))
                    }
                });
            }
        </script>
    </body>
</html>
